home *** CD-ROM | disk | FTP | other *** search
- VARARGS(5) Last changed: 10-15-98
-
-
- NNAAMMEE
- vvaarraarrggss - Variable argument list
-
- SSYYNNOOPPSSIISS
- ""##iinncclluuddee <<vvaarraarrggss..hh>>""
-
- _f_u_n_c_t_i_o_n (vvaa__aalliisstt)
- vvaa__ddccll
- vvaa__lliisstt _p_v_a_r;
- vvaa__ssttaarrtt (_p_v_a_r);
- f = vvaa__aarrgg (_p_v_a_r, _t_y_p_e);
- vvaa__eenndd (_p_v_a_r);
-
- IIMMPPLLEEMMEENNTTAATTIIOONN
- IRIX systems
-
- DDEESSCCRRIIPPTTIIOONN
- NOTE: vvaarraarrggss is being replaced by ssttddaarrgg(5). See the ssttddaarrgg(5) man
- page for the recommended method of passing variable argument lists.
-
- This set of macros provides a means of writing portable procedures
- that accept variable argument lists. Routines having variable
- argument lists [such as pprriinnttff(3)] that do not use vvaarraarrggss are
- inherently nonportable, because different machines use different
- argument passing conventions.
-
- vvaa__aalliisstt is used in a function header to declare a variable argument
- list.
-
- vvaa__ddccll is a declaration for vvaa__aalliisstt. Note that there is no semicolon
- after vvaa__ddccll.
-
- vvaa__lliisstt is a type which can be used for the variable _p_v_a_r, which is
- used to traverse the list. One such variable must always be declared.
-
- vvaa__ssttaarrtt (pvar) is called to initialize _p_v_a_r to the beginning of the
- list.
-
- vvaa__aarrgg (_p_v_a_r, _t_y_p_e) will return the next argument in the list pointed
- to by _p_v_a_r. _T_y_p_e is the type to which the expected argument will be
- converted when passed as an argument. In standard C, arguments that
- are cchhaarr or sshhoorrtt should be accessed as iinntt, ""uunnssiiggnneedd cchhaarr or
- ""uunnssiiggnneedd sshhoorrtt are converted to uunnssiiggnneedd iinntt, and ffllooaatt arguments are
- converted to ddoouubbllee. Different types can be mixed, but it is up to
- the routine to know what type of argument is expected, since it cannot
- be determined at runtime.
-
- vvaa__eenndd (_p_v_a_r) is used to finish up.
-
- Multiple traversals, each bracketed by vvaa__ssttaarrtt ... vvaa__eenndd,, are
- possible.
-
- EEXXAAMMPPLLEESS
- ##iinncclluuddee <varargs.h>
- execl(vvaa__aalliisstt)
- vvaa__ddccll
- {
- vvaa__lliisstt ap;
- cchhaarr *file;
- cchhaarr *args[100];
- iinntt argno = 0;
-
- vvaa__ssttaarrtt(ap);
- file = vvaa__aarrgg(ap, cchhaarr *);
- wwhhiillee (args[argno++] = vvaa__aarrgg(ap, cchhaarr *))
- ;;
- vvaa__eenndd(ap);
- rreettuurrnn execv(file, args);
- }
-
- BBUUGGSS
- It is up to the calling routine to determine how many arguments there
- are, since it is not possible to determine this from the stack frame.
- For example, eexxeeccll passes a 0 to signal the end of the list. pprriinnttff
- can tell how many arguments are supposed to be there by the format.
-
- The macros vvaa__ssttaarrtt and vvaa__eenndd may be arbitrarily complex; for
- example, vvaa__ssttaarrtt might contain an opening brace, which is closed by a
- matching brace in vvaa__eenndd. Thus, they should only be used where they
- could be placed within a single complex statement.
-
- SSEEEE AALLSSOO
- ssttddaarrgg(5)
-
-